
package com.gzbsoft.sc.common.utils;
import cn.hutool.http.HttpStatus;
import org.springframework.data.domain.Page;

import java.util.HashMap;
import java.util.List;
/**
 * 返回数据
 *
 * @author Mark sunlightcs@gmail.com
 */
public class R extends HashMap<String, Object> {
    public static R error() {
        return error(HttpStatus.HTTP_INTERNAL_ERROR, "未知异常，请联系管理员");
    }
    public static R error(String msg) {
        return error(100, msg);
    }
    public static R error(int code, String msg) {
        R r = new R();
        r.put("code",code);
        r.put("msg",msg);
        return r;
    }
    public static R ok(String msg) {
        R r = new R();
        r.put("code",0);
        r.put("msg",msg);
        return r;
    }
    public static R ok() {
        R r = new R();
        r.put("code",0);
        return r;
    }

    public void setMsg(String msg) {
        this.put("msg", msg);
    }
    public R setObj(Object obj) {
        this.put("obj", obj);
        return this;
    }
    public R setList(List<?> list) {
        this.put("list", list);
        return this;
    }
    public R setPage(Page page) {
        this.put("page", page);
        return this;
    }
    public void setCode(int code) {
        this.put("code",code);
    }
}
